/*   1:    */ package org.jetbrains.generate.tostring.view;
/*   2:    */ 
/*   3:    */

import com.intellij.openapi.options.ConfigurationException;
import com.intellij.openapi.options.UnnamedConfigurable;
import com.intellij.openapi.ui.NamedItemsListEditor;
import com.intellij.openapi.ui.Namer;
import com.intellij.openapi.util.Cloner;
import com.intellij.openapi.util.Comparing;
import com.intellij.openapi.util.Factory;
import gnu.trove.Equality;
import org.jetbrains.annotations.Nls;
import org.jetbrains.annotations.NonNls;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.generate.tostring.template.TemplateResource;
import org.jetbrains.generate.tostring.template.TemplatesManager;

import java.util.ArrayList;

/*   4:    */
/*   5:    */
/*   6:    */
/*   7:    */
/*   8:    */
/*   9:    */
/*  10:    */
/*  11:    */
/*  12:    */
/*  13:    */
/*  14:    */
/*  15:    */
/*  16:    */
/*  17:    */ 
/*  18:    */ public class TemplatesPanel
/*  19:    */   extends NamedItemsListEditor<TemplateResource>
/*  20:    */ {
/*  21: 39 */   private static final Namer<TemplateResource> a = new Namer()
/*  22:    */   {
/*  23:    */     public String getName(TemplateResource paramAnonymousTemplateResource)
/*  24:    */     {
/*  25: 41 */       return paramAnonymousTemplateResource.getFileName();
/*  26:    */     }
/*  27:    */     
/*  28:    */     public boolean canRename(TemplateResource paramAnonymousTemplateResource)
/*  29:    */     {
/*  30: 45 */       return !paramAnonymousTemplateResource.isDefault();
/*  31:    */     }
/*  32:    */     
/*  33:    */     public void setName(TemplateResource paramAnonymousTemplateResource, String paramAnonymousString)
/*  34:    */     {
/*  35: 49 */       paramAnonymousTemplateResource.setFileName(paramAnonymousString);
/*  36:    */     }
/*  37:    */   };
/*  38: 53 */   private static final Factory<TemplateResource> b = new Factory()
/*  39:    */   {
/*  40:    */     public TemplateResource create()
/*  41:    */     {
/*  42: 55 */       return new TemplateResource();
/*  43:    */     }
/*  44:    */   };
/*  45: 59 */   private static final Cloner<TemplateResource> c = new Cloner()
/*  46:    */   {
/*  47:    */     public TemplateResource cloneOf(TemplateResource paramAnonymousTemplateResource)
/*  48:    */     {
/*  49: 61 */       if (paramAnonymousTemplateResource.isDefault()) {
/*  50: 61 */         return paramAnonymousTemplateResource;
/*  51:    */       }
/*  52: 62 */       return copyOf(paramAnonymousTemplateResource);
/*  53:    */     }
/*  54:    */     
/*  55:    */     public TemplateResource copyOf(TemplateResource paramAnonymousTemplateResource)
/*  56:    */     {
/*  57: 66 */       TemplateResource localTemplateResource = new TemplateResource();
/*  58: 67 */       localTemplateResource.setFileName(paramAnonymousTemplateResource.getFileName());
/*  59: 68 */       localTemplateResource.setTemplate(paramAnonymousTemplateResource.getTemplate());
/*  60: 69 */       return localTemplateResource;
/*  61:    */     }
/*  62:    */   };
/*  63: 73 */   private static final Equality<TemplateResource> d = new Equality()
/*  64:    */   {
/*  65:    */     public boolean equals(TemplateResource paramAnonymousTemplateResource1, TemplateResource paramAnonymousTemplateResource2)
/*  66:    */     {
/*  67: 75 */       return (Comparing.equal(paramAnonymousTemplateResource1.getTemplate(), paramAnonymousTemplateResource2.getTemplate())) && (Comparing.equal(paramAnonymousTemplateResource1.getFileName(), paramAnonymousTemplateResource2.getFileName()));
/*  68:    */     }
/*  69:    */   };
/*  70:    */   
/*  71:    */   public TemplatesPanel()
/*  72:    */   {
/*  73: 80 */     super(a, b, c, d, new ArrayList(TemplatesManager.getInstance().getAllTemplates()));
/*  74:    */   }
/*  75:    */   
/*  76:    */   @Nls
/*  77:    */   public String getDisplayName()
/*  78:    */   {
/*  79: 88 */     return "Templates";
/*  80:    */   }
/*  81:    */   
/*  82:    */   protected String subjDisplayName()
/*  83:    */   {
/*  84: 93 */     return "template";
/*  85:    */   }
/*  86:    */   
/*  87:    */   @Nullable
/*  88:    */   @NonNls
/*  89:    */   public String getHelpTopic()
/*  90:    */   {
/*  91: 99 */     return null;
/*  92:    */   }
/*  93:    */   
/*  94:    */   public boolean isModified()
/*  95:    */   {
/*  96:104 */     return (super.isModified()) || (!Comparing.equal(TemplatesManager.getInstance().getDefaultTemplate(), getSelectedItem()));
/*  97:    */   }
/*  98:    */   
/*  99:    */   protected boolean canDelete(TemplateResource paramTemplateResource)
/* 100:    */   {
/* 101:109 */     return !paramTemplateResource.isDefault();
/* 102:    */   }
/* 103:    */   
/* 104:    */   protected UnnamedConfigurable createConfigurable(TemplateResource paramTemplateResource)
/* 105:    */   {
/* 106:113 */     return new ToStringTemplateConfigurable(paramTemplateResource);
/* 107:    */   }
/* 108:    */   
/* 109:    */   public void apply()
/* 110:    */     throws ConfigurationException
/* 111:    */   {
/* 112:118 */     super.apply();
/* 113:119 */     TemplatesManager.getInstance().setTemplates(getItems());
/* 114:120 */     TemplateResource localTemplateResource = (TemplateResource)getSelectedItem();
/* 115:121 */     if (localTemplateResource != null) {
/* 116:122 */       TemplatesManager.getInstance().setDefaultTemplate(localTemplateResource);
/* 117:    */     }
/* 118:    */   }
/* 119:    */ }



/* Location:           E:\idea\

 * Qualified Name:     org.jetbrains.generate.tostring.view.TemplatesPanel

 * JD-Core Version:    0.7.0.1

 */